package com.sky.wsp.sql.scanner.patterns.func;

import com.sky.wsp.sql.scanner.patterns.BasePattern;
import com.sky.wsp.sql.scanner.vo.MatchResult;

import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

public class Mysql2KingbaseFuncPattern extends BasePattern {
    public Mysql2KingbaseFuncPattern() {
        Map<String, Pattern> patterns = getPatterns();
        patterns.put("truncate", Pattern.compile("[(\\s]+(truncate)[\\s]*[(]+"));
        patterns.put("convert", Pattern.compile("[(\\s]+(convert)[\\s]*[(]+"));
        patterns.put("export_set", Pattern.compile("[(\\s]+(export_set)[\\s]*[(]+"));
        patterns.put("format", Pattern.compile("[(\\s]+(format)[\\s]*[(]+"));
        patterns.put("instr", Pattern.compile("[(\\s]+(instr)[\\s]*[(]+"));
        patterns.put("left", Pattern.compile("[(\\s]+(left)[\\s]*[(]+"));
        patterns.put("length", Pattern.compile("[(\\s]+(length)[\\s]*[(]+"));
        patterns.put("ltrim", Pattern.compile("[(\\s]+(ltrim)[\\s]*[(]+"));
        patterns.put("make_set", Pattern.compile("[(\\s]+(make_set)[\\s]*[(]+"));
        patterns.put("rtrim", Pattern.compile("[(\\s]+(rtrim)[\\s]*[(]+"));
        patterns.put("substr", Pattern.compile("[(\\s]+(substr)[\\s]*[(]+"));
        patterns.put("extract", Pattern.compile("[(\\s]+(extract)[\\s]*[(]+"));
        patterns.put("now", Pattern.compile("[(\\s]+(now)[\\s]*[(]+"));
        patterns.put("str_to_date", Pattern.compile("[(\\s]+(str_to_date)[\\s]*[(]+"));
        patterns.put("json_arrayagg", Pattern.compile("[(\\s]+(json_arrayagg)[\\s]*[(]+"));
        patterns.put("json_objectagg", Pattern.compile("[(\\s]+(json_objectagg)[\\s]*[(]+"));
        patterns.put("json_array", Pattern.compile("[(\\s]+(json_array)[\\s]*[(]+"));
        patterns.put("json_extract", Pattern.compile("[(\\s]+(json_extract)[\\s]*[(]+"));
        patterns.put("json_object", Pattern.compile("[(\\s]+(json_object)[\\s]*[(]+"));
        patterns.put("json_table", Pattern.compile("[(\\s]+(json_table)[\\s]*[(]+"));
        patterns.put("date_format", Pattern.compile("[(\\s]+(date_format)[\\s]*[(]+"));
        patterns.put("date", Pattern.compile("[(\\s]+(date)[\\s]*[(]+"));
        patterns.put("sha2", Pattern.compile("[(\\s]+(sha2)[\\s]*[(]+"));
        patterns.put("unhex", Pattern.compile("[(\\s]+(unhex)[\\s]*[(]+"));
        patterns.put("hex", Pattern.compile("[(\\s]+(hex)[\\s]*[(]+"));
    }

    @Override
    public List<MatchResult> match(String content) {
        // 方法名不区分大小写，所有要转小写进行匹配
        return super.match(content.toLowerCase());
    }
}
